#include "guish.hpp"
#ifndef PTYMANAGER_HPP
#define PTYMANAGER_HPP
#include "IOManager.hpp"

class PtyManager
	:public IOUser
{
public:
	PtyManager();
	~PtyManager();
	
	PseudoTerminal *getNewPty(StreamSender *outputHandler, int width, int height);
	void stopPty(PseudoTerminal *pty);
	void restartPty(PseudoTerminal *pty, StreamSender *outputHandler);
	void discardPty(PseudoTerminal *pty);
	
	void prepareSelect(int priority, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, int *maxfd);
	void postSelect(int priority, fd_set *readfds, fd_set *writefds, fd_set *exceptfds);
	void readAllPty(PseudoTerminal *pty);
	
	void resizeAll(int width, int height);
	
protected:
	pthread_mutex_t lock;
	map<PseudoTerminal*, StreamSender*> ptys;
};

extern PtyManager *ptyManager;

#endif
